<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- 1. 添加React依赖 -->
  <script crossorigin src="https://unpkg.com/react@18.3.1/umd/react.development.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.development.js"></script>
  <script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>

  <div id="root"></div>

  <script type="text/babel">
    // 渲染hello world
    const root = ReactDOM.createRoot(document.querySelector('#root'))
    let message = 'Hello World'
    function handleClick () {
      console.log('button click')
      // 1. 修改数据
      message = 'Hello React'
      // 2. 重新渲染页面
      renderRoot()
    }
    function renderRoot () {
      root.render((
        <div>
          <h2>{ message }</h2>
          <button onClick={handleClick}>修改文本</button>
        </div>
      ))
    }
    renderRoot()
  </script>
</body>
</html>